<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('综合数据')" />
    <th:block th:include="include :: layout-latest-css" />
    <th:block th:include="include :: ztree-css" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="gray-bg">
<div class="ui-layout-west">
    <div class="box box-main">
        <div class="box-header">
            <div class="box-title">
                <i class="fa icon-grid"></i> 住户资料
            </div>
            <div class="box-tools pull-right">
                <button type="button" class="btn btn-box-tool" id="btnExpand" title="展开" style="display:none;"><i class="fa fa-chevron-up"></i></button>
                <button type="button" class="btn btn-box-tool" id="btnCollapse" title="折叠"><i class="fa fa-chevron-down"></i></button>
                <button type="button" class="btn btn-box-tool" id="btnRefresh" title="刷新"><i class="fa fa-refresh"></i></button>
            </div>
        </div>
        <div class="ui-layout-content">
            <div id="tree" class="ztree"></div>
        </div>
    </div>
</div>
<div class="ui-layout-center">
    <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <input type="hidden" id="locationId" name="locationId" th:value="${locationId}">

                    <div class="select-list">
                        <ul>
                            <li>
                                <label>地址名称：</label>
                                <input type="text" name="locationName"/>
                            </li>
                          <!--  <li class="select-time">
                                <label>采集时间：</label>
                                <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginTime]"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endTime]"/>
                            </li>-->

                            <li>
                                <label>缴费状态：</label>
                                <select id="status" name="status">
                                    <option value="">所有</option>
                                    <option value="1">缴费</option>
                                    <option value="0">未缴费</option>
                                </select>
                            </li>
                            <li class="select-time-long">
                                <label>采集时间：</label>
                                <input type="text" class="input-sm form-control" id="datetimepicker-startTime" name="params[beginTime]" placeholder="开始时间" th:value="${beginTime}"/>
                                <span>-</span>
                                <input type="text" class="input-sm form-control" id="datetimepicker-endTime" name="params[endTime]" placeholder="结束时间" th:value="${endTime}"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>


            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
</div>

<th:block th:include="include :: footer" />
<th:block th:include="include :: datetimepicker-js" />
<th:block th:include="include :: bootstrap-table-export-js" />
<th:block th:include="include :: bootstrap-table-auto-refresh-js" />
<th:block th:include="include :: bootstrap-table-print-js" />
<th:block th:include="include :: layout-latest-js" />
<th:block th:include="include :: ztree-js" />

<script th:inline="javascript">
    var prefix = ctx + "base/location/data";
    var editFlag = [[${@permission.hasPermi('base:location:edit')}]];

    $(function() {
        var panehHidden = false;
        if ($(this).width() < 769) {
            panehHidden = true;
        }
        $('body').layout({ initClosed: panehHidden, west__size: 185 });
        queryInfoList();
        queryLocationTree();
    });

    function queryInfoList() {
        var options = {
            url: prefix + "/list",
            modalName: "综合数据",
            showSearch: false,

            showExport: true,

            columns: [
                {
                    field: 'locationName',
                    title: '地址名称'
                },
                {
                    field: 'meterId',
                    title: '热表ID',
                    sortable: true,
                    formatter: function(value, row, index) {
                        if(row.meterId == null){
                            return '-'
                        }else
                        return '<a href="javascript:void(0)" onclick="detailm(\'' + row.meterId + '\')">' + value + '</a>';
                    }
                },
                {
                    field: 'heat',
                    title: '累计热量',
                    sortable: true
                },
                {
                    field: 'flow',
                    title: '累计流量',
                    sortable: true
                },
                {
                    field: 'power',
                    title: '功率',
                    sortable: true
                },
                {
                    field: 'instant',
                    title: '瞬时流量',
                    sortable: true
                },
                {
                    field: 'inlet',
                    title: '进水温度',
                    sortable: true
                },
                {
                    field: 'outlet',
                    title: '回水温度',
                    sortable: true
                },
                {
                    field: 'meterWork',
                    title: '工作时间',
                    sortable: true
                },
                {
                    field: 'gatherTime',
                    title: '热表时间',
                    sortable: true
                },
                {
                    field: 'meterCreate',
                    title: '热表采集时间',
                    sortable: true
                },
                {
                    field: 'valveId',
                    title: '阀门ID',
                    formatter: function(value, row, index) {
                        if(row.valveId == null){
                            return '-';
                        }else
                        return '<a href="javascript:void(0)" onclick="detailv(\'' + row.valveId + '\')">' + value + '</a>';
                    },
                    sortable: true
                },
                {
                    field: 'max',
                    title: '温度上限',
                    sortable: true
                },
                {
                    field: 'min',
                    title: '温度下限',
                    sortable: true
                },
                {
                    field: 'temp',
                    title: '设置温度',
                    sortable: true
                },
                {
                    field: 'indoor',
                    title: '室内温度',
                    sortable: true
                },
                {
                    field: 'valveWork',
                    title: '阀开时间',
                    sortable: true
                },
                {
                    field: 'aperture',
                    title: '阀门开度',
                    sortable: true
                },
                {
                    field: 'onlineStatus',
                    title: '温控器在线状态',
                    sortable: true,
                    formatter: function(value, item, index) {
                        if (item.onlineStatus == '1') {
                            return '<span class="label label-success">在线</span>';
                        }
                        else {
                            return '<span class="label label-danger">离线</span>';
                        }
                    }
                },
                {
                    field: 'valveCreate',
                    title: '阀门采集时间',
                    sortable: true
                },
                {
                    visible: editFlag != 'hidden',
                    title: '供暖状态',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return locationUser(row);
                    }
                }

                ]
        };
        $.table.init(options);
    }

    function queryParams(params) {
        var search = $.table.queryParams(params);
        search.locationId = $("#locationId").val();
        return search;
    }
    /* 数据展示 */
    function detailv(valveId) {
        var url = ctx + 'report/valve/' + valveId;
        $.modal.openTab("阀门数据展示", url);

    }

    /* 数据展示 */
    function detailm(meterId) {
        var url = ctx + 'report/meter/' + meterId;
        $.modal.openTab("热表数据展示", url);
    }

    function queryLocationTree()
    {
        var url = ctx + "base/location/treeData";
        var options = {
            url: url,
            expandLevel: 2,
            onClick : zOnClick
        };
        $.tree.init(options);

        function zOnClick(event, treeId, treeNode) {
            $("#locationId").val(treeNode.id);
            $.table.search();
        }
    }

    $('#btnExpand').click(function() {
        $._tree.expandAll(true);
        $(this).hide();
        $('#btnCollapse').show();
    });

    $('#btnCollapse').click(function() {
        $._tree.expandAll(false);
        $(this).hide();
        $('#btnExpand').show();
    });

    $('#btnRefresh').click(function() {
        queryLocationTree();
    });

    /**
     * 热表数据采集
     */
    function check(){
        var locationId = $("#locationId").val();
        if(locationId==''){
            $.modal.alertWarning("请先选择采集地址");
            return;
        }
        $.operate.post(prefix + "/check", { "locationId": locationId });
    }

    /* 用户状态显示 */
    function locationUser(row) {
        if (row.status == 0) {
            return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.locationId + '\')"></i> ';
        } else {
            return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.locationId + '\')"></i> ';
        }
    }
    /* 用户管理-停用 */
    function disable(locationId) {
        $.modal.confirm("确认要停用用户吗？", function() {
            $.operate.post(ctx + "base/location/changeStatus", { "locationId": locationId, "status": 0 });
        })
    }

    /* 用户管理启用 */
    function enable(locationId) {
        $.modal.confirm("确认要启用用户吗？", function() {
            $.operate.post(ctx + "base/location/changeStatus", { "locationId": locationId, "status": 1 });
        })
    }

    $("#datetimepicker-startTime").datetimepicker({
        format: 'yyyy-mm-dd hh:ii',
        autoclose: true,
        endDate : new Date(),
    }).on('changeDate', function(event) {
        event.preventDefault();
        event.stopPropagation();
        var startTime = event.date;
        $('#datetimepicker-endTime').datetimepicker('setStartDate', startTime);
    });

    $("#datetimepicker-endTime").datetimepicker({
        format: 'yyyy-mm-dd hh:ii',
        autoclose: true,
        endDate : new Date(),
    }).on('changeDate', function(event) {
        event.preventDefault();
        event.stopPropagation();
        var endTime = event.date;
        $("#datetimepicker-startTime").datetimepicker('setEndDate', endTime);
    });
</script>
</body>
</html>